Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

form-data

Package Overview
Dependencies
Maintainers
6
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

form-data

A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.

  • 2.5.2
  • v2-backport
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
75M
decreased by-8.77%
Maintainers
6
Weekly downloads
 
Created

What is form-data?

The form-data npm package is used to create `multipart/form-data` streams that can be used to perform HTTP requests with file uploads and other form data. It is commonly used with request libraries to submit forms and upload files to a server.

What are form-data's main functionalities?

Appending fields

This feature allows you to append key-value pairs to the form-data object, which can represent text fields in a form.

const FormData = require('form-data');
const form = new FormData();
form.append('username', 'exampleUser');
form.append('password', 'examplePassword');

Appending files

This feature allows you to append files to the form-data object, which can be used to upload files to a server.

const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('file', fs.createReadStream('/path/to/file.txt'), 'file.txt');

Custom headers

This feature allows you to retrieve custom headers required for submitting the form-data object, including the correct `Content-Type` header with the boundary.

const FormData = require('form-data');
const form = new FormData();
const customHeaders = form.getHeaders({'custom-header': 'value'});
// customHeaders can now be used with an HTTP client to send the form with custom headers.

Piping to a HTTP request

This feature demonstrates how to pipe the form-data directly to an HTTP request, which is useful for uploading files and submitting forms.

const FormData = require('form-data');
const http = require('http');
const form = new FormData();
form.append('field', 'value');

const request = http.request({
  method: 'post',
  host: 'example.com',
  path: '/upload',
  headers: form.getHeaders()
});

form.pipe(request);

Other packages similar to form-data

FAQs

Package last updated on 10 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc